package com.duzilin.ehrecyclerview.demo;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.duzilin.ehrecyclerview.R;
import com.duzilin.ehrecyclerview.Wrapper.RecyclerViewAdapterPlus;

import java.util.ArrayList;
import java.util.List;

public class HeaderAndFooterActivity extends Activity implements RecyclerViewAdapterPlus.OnItemClickListener<String>{

    private RecyclerView recyclerView;
    private MyAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_header_and_footer);
        recyclerView = findViewById(R.id.recyclerview);
        adapter = new MyAdapter();
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        initData();
        initHeader();
        initFooter();
        adapter.setOnItemClickLinstener(this);

    }

    private void initHeader() {
        View header = this.getLayoutInflater().inflate(R.layout.layout_header, recyclerView , false);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(HeaderAndFooterActivity.this , "Header Click!" , Toast.LENGTH_SHORT).show();
            }
        });
        adapter.setHeaderView(header);

    }
    private void initFooter() {
        View footer = this.getLayoutInflater().inflate(R.layout.layout_footer, recyclerView , false);
        footer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(HeaderAndFooterActivity.this , "Footer Click!" , Toast.LENGTH_SHORT).show();
            }
        });
        adapter.setFooterView(footer);

    }

    private void initData() {
        List<String> data = new ArrayList<>();
        for (int i = 0 ; i<6 ; i++){
            data.add(i + "");
        }
        adapter.addDatas(data);
    }


    @Override
    public void onItemClick(int position, String data) {
        Toast.makeText(this , data , Toast.LENGTH_SHORT).show();
    }
}
